<template>
  <div>

    <el-table :data="tableData" style="width: 99%" max-height="800px" @selection-change="handleSelectionChange"
      @row-click="handle">

      <el-table-column type="selection" width="55" align="center">
      </el-table-column>
      <el-table-column prop="template" label="使用模版" width="120" align="center">
      </el-table-column>
      <el-table-column prop="cTime" label="发送时间" width="200" align="center">
      </el-table-column>
      <el-table-column prop="title" label="通知标题" width="100" align="center">
      </el-table-column>

      <el-table-column prop="context" label="发送内容" width="550" align="center">
      </el-table-column>
   
      <el-table-column prop="remark" label="备注" width="120" align="center">
      </el-table-column>
      <el-table-column prop="address" label="单位" width="200" align="center">
      </el-table-column>
      <el-table-column>
        <template slot-scope="scope">
          <el-button size="mini" type="danger" v-if="!scope.row.editing" icon="el-icon-delete"
            @click.stop="open(scope.row)">删除
          </el-button>
        </template>
      </el-table-column>

    </el-table>
  </div>
</template>
<script>
  import {
    getToken,
    getMessages,
    deleteMessage
  } from "@/api/user/user.js";
  export default {
    data() {
      let $domain = process.env.VUE_APP_BASE_API;
      return {
        tableData: [], //表格数据
        searchName: "", //搜索名
        pages: 0,
        domain: $domain,
        thispage: 1,
        token: ''
      };
    },
    created() {
      this.requestuser(1)
    },
    methods: {
      query() {
        let _that = this;
        let data = {
          field: "tel",
          value: _that.searchName,
          op: "=",
        }
        getuser(data).then((res) => {
          _that.tableData = res.template_list
        })
      },
      handleSelectionChange(val) {
        this.multipleSelection = val
      },
      open(row) {
        console.log('row:', row)
        this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.handleDelete(row.id)

        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      handleDelete(id) {
        let data = {
          field: 'id',
          op: '=',
          value: id
        }
        deleteMessage(data).then((res) => {
          console.log('请求成功：', res);
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
           this.requestuser(1)
        })
      },
      //请求页面第一个
      requestuser(pages) {
        let _that = this;
        const admin = JSON.parse(sessionStorage.getItem('admin'));
        console.log('admin:', admin);
        let data = {
          field: 'o_id',
          op: '=',
          value: admin.o_id
        }
        getMessages(data).then((res) => {
          console.log('请求成功：', res);
          _that.tableData = res;
        })
      },
      handle(row, event, column) {
        console.log(row.id)
        this.$router.push({
          name: "onepage",
          query: {
            id: row.id,
          }
        })
      }
      // requestpage() {
      //   let _that = this
      //   let data = {
      //     field: "u_id",
      //     op: ">",
      //     value: 0,
      //   }
      //   usernum(data).then((res) => {
      //     _that.pages = res
      //   })
      // },
      // pagechange(page) {
      //   this.requestuser(page)
      //   this.thispage = page
      // },
    },
  }
</script>

<style scoped>
  .demo-table-expand {
    font-size: 0;
  }

  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }

  .demo-table-expand .el-form-item {
    margin-bottom: 0;
    width: 100%;
    white-space: pre-line;
  }

  .idc {
    margin-right: 15px;
    width: 40%;
    height: 300px;
  }

  .pagectn {
    width: 100%;
    background-color: #fff;
    padding: 5px;
    position: fixed;

    z-index: 100;
  }

  .idcardbox {
    display: flex;
  }
</style>
